﻿/*
 * Copyright (c) 2025 HiEasyX
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/**
 * \file Button.cpp
 * \brief The example of the usage of button control
 */

#include <include/hex.h>
#include <include/impl/EasyX/hex_impl_easyx.h>

int main() {
	initgraph(640, 480);

	BeginBatchDraw();

	HX::HXInitForEasyX();
	HX::SetBuffer(GetWorkingImage());

	setbkcolor(RGB(180, 180, 180));

	HX::WindowProfile windowProfile;
	windowProfile.Size = { 600, 400 };

	while (true) {
		cleardevice();

		HX::HXBegin();

		ExMessage message{};
		while (peekmessage(&message)) {
			HX::PushMessage(HX::GetHXMessage(&message));
		}

		HX::Window(HXStr("按钮控件示例"), windowProfile);

		static int               count = 0;
		static HX::ButtonProfile buttonProfile;
		HX::BeginSameLine();
		if (HX::Button(HXStr("这是一个默认的按钮，其大小跟随其标题文本而缩放"), buttonProfile)) {
			// 按钮被按下
			++count;
		}
		HX::Text(HXStr("按钮按下计次: ") + ToHXString(count));
		HX::EndSameLine();

		static HX::ButtonProfile buttonProfile2;
		buttonProfile2.Size.Y = 40;
		HX::Button(HXStr("这是一个自定义高的按钮，宽依然自动调整"), buttonProfile2);

		static HX::ButtonProfile buttonProfile3;
		buttonProfile3.Size.X = 500;
		HX::Button(HXStr("这是一个自定义宽的按钮，宽依然自动调整"), buttonProfile3);

		static HX::ButtonProfile buttonProfile4;
		HX::Button(HXStr("这个按钮测试资料结构体的功能"), buttonProfile4);
		if (buttonProfile4.OnPressed) {
			MessageBox(GetHWnd(), HXStr("你点击了按钮"), HXStr("提示"), MB_OK);
		}
		if (buttonProfile4.OnHold) {
			HX::Text(HXStr("按钮被按住！"));
		}
		if (buttonProfile4.OnHover) {
			HX::Text(HXStr("鼠标悬浮在按钮之上！"));
		}

		HX::End();
		HX::Render();

		FlushBatchDraw();

		Sleep(1);
	}

	return 0;
}